<?php

class Deposit_admins extends CI_Controller {

    function __construct() {
        parent::__construct();
        if ($this->session->userdata('logged_in')) {
            $session_data = $this->session->userdata('logged_in');
            $data['username'] = $session_data['username'];
        } else {
            redirect('user_login/user', 'refresh');
        }

        $this->load->model('deposit');
        $this->load->model('user');
        $this->load->model('costumer');
        $this->load->model('user_role');
        $this->load->library('user_id');
        $this->load->helper('user_helper');
        $this->load->helper('deposit_helper');

        if ($this->user_id->cek() == 0) {
            redirect('user_login/user', 'refresh');
        }
    }

    function index() {
        $data['id'] = $this->user_id->id();
        $data['i'] = 1;
        $config = array();
        $config["base_url"] = base_url() . "deposit_admins/index";
        $config["total_rows"] = $this->deposit->record_count();
        $config["per_page"] = 15;
        $config["uri_segment"] = 3;

        $this->pagination->initialize($config);

        $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
        $data['access'] = $this->user_role->access($this->user_id->cek());
        $data["rows"] = $this->deposit->fetch_costumer($config["per_page"], $page);
        $data["links"] = $this->pagination->create_links();

        $data['content'] = 'deposit_admin/index';
        $this->load->view('template/user', $data);
    }

    function show() {
        $id = $this->uri->segment(3);
        $data['access'] = $this->user_role->access($this->user_id->cek());
        $data['rows'] = $this->deposit->show($id);
        $data['content'] = 'deposits/show';
        $this->load->view('template/costumer', $data);
    }

    function show_deposit() {
        $id = $this->uri->segment(3);
        $data['id'] = $this->user_id->id();
         $data['access'] = $this->user_role->access($this->user_id->cek());
//        $id = $this->uri->segment(3);
//        $data['access'] = $this->user_role->access($this->user_id->cek());
        $data['rows'] = $this->deposit->show_deposit($id);
        $data['content'] = 'deposit_admin/show';
        $this->load->view('template/user', $data);
    }

    function add() {
        $this->load->model('admin_bank_model');
        $data['access'] = $this->user_role->access($this->user_id->cek());
        $data['banks'] = $this->admin_bank_model->index();
        $data['content'] = 'deposits/new';
        $this->load->view('template/costumer', $data);
    }

    function create() {
        $id_costumer = $this->id();
        $date = date('Y-m-d');
        $bank_name = $this->input->post('bank_name', TRUE);
        $costumer_bank = $this->input->post('costumer_bank', TRUE);
        $costumer_an = $this->input->post('costumer_an', TRUE);
        $deposit = $this->input->post('deposit', TRUE);
        $this->deposit->create($id_costumer, $bank_name, $costumer_bank, $costumer_an, $deposit, $date);
    }

    function confirm() {
        #cek
        $access = $this->user_role->access($this->user_id->cek());
        $this->user_role->chek($access, 'deposit_edit');

        $url = $this->uri->segment(3);
        $url = explode('.', $url);
        $id = $url[0];
        $id_costumer = $url[1];
        $status = 1;
        
        $email_user = $this->costumer->get_email($id_costumer);
//        $email_user = array($email_user);
        $message = $this->load->view('costumers/email_deposit_user', '', TRUE);
        $this->load->library('email');
        $this->email->set_mailtype("html");
        $this->email->from('stasiuntiketonline.com');

        //email

//        $list = array_merge($email, $email_user);
        $this->email->to($email_user);
        $this->email->cc('');
        $this->email->subject('Deposit Sukses');
        $this->email->message($message);
        $this->email->send();
        
        exit;
//        $this->deposit->confirm($id, $status);
    }

    function not_aprove() {
        #cek
        $access = $this->user_role->access($this->user_id->cek());
        $this->user_role->chek($access, 'deposit_delete');

        $id = $this->uri->segment(3);
        $status = 2;
        $this->deposit->confirm($id, $status);
    }

}

?>
